home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / wf120.zip / WD.C < prev    next >
C/C++ Source or Header  |  1992-01-06  |  5KB  |  158 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: wd.c
  5.    Author: J. Kercheval
  6.    Created: Sun, 03/31/1991  14:59:48
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Sat, 04/20/1991  20:32:50  create wd (Wild Directory)
  12.    J. Kercheval  Sat, 04/20/1991  21:24:34  This is V1.13 of WD
  13.    D. Kirschbaum Mon, 05/13/1991  16:30:00  v1.14 Turbo C-related patches
  14.    J. Kercheval  Mon, 05/13/1991  21:17:23  usage statement cleanup
  15.    J. Kercheval  Fri, 05/17/1991  22:54:26  use FileInfo typedef
  16. */
  17.  
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22. #include "wildfile.h"
  23.  
  24. #ifndef BOOLEAN
  25. #define BOOLEAN int
  26. #define TRUE 1
  27. #define FALSE 0
  28. #endif
  29.  
  30. #ifdef __TURBOC__
  31. #define _splitpath fnsplit
  32. #endif
  33.  
  34. #define Author "J. Kercheval"
  35. #define Version "Wild Card Simple Directory Lister V1.14"
  36.  
  37.  
  38. /*----------------------------------------------------------------------------
  39.  *
  40.  * Print Usage
  41.  *
  42.  ---------------------------------------------------------------------------*/
  43.  
  44. void Usage(char *progname)
  45. {
  46.     char drive[5], dir[255], fname[10], ext[5];
  47.  
  48.     _splitpath(progname, drive, dir, fname, ext);
  49.     fprintf(stderr, "\n%s -- %s\n\n", Version, Author);
  50.     fprintf(stderr,
  51.             "Usage: %s [ -h | -? ] | [{FILENAME}] \n\n", fname);
  52.     fprintf(stderr,
  53.       "  Used to list files using *IX shell type globbing (Wild Cards).\n");
  54.     fprintf(stderr,
  55.       "  Multiple filenames may be listed on the command line.  You may\n");
  56.     fprintf(stderr,
  57.          "  use either \\ or / as directory delimiters.  If you wish to\n");
  58.     fprintf(stderr,
  59.       "  match a / or a \\ then they must be literally escaped within a\n");
  60.     fprintf(stderr,
  61.     "  range ([..]) construct. (ie. [\\]] would match ']').  The allowed\n");
  62.     fprintf(stderr,
  63.             "  special characters for wild card matching are:\n");
  64.     fprintf(stderr,
  65.             "   `*' matches any sequence of characters (zero or more)\n");
  66.     fprintf(stderr,
  67.             "   `?' matches any character\n");
  68.     fprintf(stderr,
  69.             "   [SET] matches any character in the specified set\n");
  70.     fprintf(stderr,
  71.     "   [!SET] or [^SET] matches any character not in the specified set\n");
  72.     fprintf(stderr,
  73.             "   \\ is allowed within a set to escape a character like ']' or '-'\n\n");
  74.     fprintf(stderr, "   ie. %s\n", fname);
  75.     fprintf(stderr, "   ie. %s t*s*t\n", fname);
  76.     fprintf(stderr, "   ie. %s *t \\*.bat\n", fname);
  77.     fprintf(stderr, "   ie. %s \\bin\\[a-e]?[!t]\n", fname);
  78.     fprintf(stderr, "   ie. %s *f*.[bde-hxyz]*\n\n", fname);
  79.     exit(1);
  80. }
  81.  
  82.  
  83. /*----------------------------------------------------------------------------
  84.  *
  85.  * wd displays all files matching the passed pathname in single column
  86.  * similar to the DOS DIR command.
  87.  *
  88.  ---------------------------------------------------------------------------*/
  89.  
  90. void wd(char *pathname)
  91. {
  92.     FileInfo ff;                /* the file find structure */
  93.  
  94.     /* initialize ff */
  95.     strcpy(ff.file_pattern, pathname);
  96.     ff.file_attributes = _FA_NORMAL | _FA_READONLY | _FA_ARCHIVE |
  97.         _FA_HIDDEN | _FA_SYSTEM | _FA_DIRECTORY;
  98.  
  99.     /* print path to output */
  100.     fprintf(stdout, "\nFile(s) matching \"%s\"\n\n", pathname);
  101.  
  102.     /* find the initial file matching pattern */
  103.     if (find_firstfile(&ff)) {
  104.  
  105.         /* loop through all matching files in the parameter */
  106.         do {
  107.  
  108.             /* print the info */
  109.             fprintf(stdout, "%s\n", ff.file.name);
  110.  
  111.         } while (find_nextfile(&ff));
  112.     }
  113. }
  114.  
  115.  
  116. /*----------------------------------------------------------------------------
  117.  *
  118.  * main loops through the parameter list and calls wd
  119.  *
  120.  ---------------------------------------------------------------------------*/
  121.  
  122. int main(int argc, char *argv[])
  123. {
  124.  
  125.     /* if not enough parameters than Usage() */
  126.     if (argc < 2) {
  127.         wd("*");
  128.         exit(0);
  129.     }
  130.  
  131.     /* enter the main loop */
  132.     for (argc--, argv++; argc; argc--, argv++) {
  133.  
  134.         /* parse the argument list */
  135.         switch (argv[0][0]) {
  136.  
  137.             case '-':
  138.                 switch (argv[0][1]) {
  139.                     case 'h':
  140.                     case 'H':
  141.                     case '?':
  142.  
  143.                         Usage((--argv)[0]);
  144.                         break;
  145.                 }
  146.                 break;
  147.  
  148.                 /* this is a file parameter */
  149.             default:
  150.                 wd(*argv);
  151.                 break;
  152.         }
  153.     }
  154.  
  155.     /* successful exit */
  156.     return (0);
  157. }
  158.